package com.ruoyi.classify.service.impl;

import java.util.*;

import com.ruoyi.digest.mapper.HsGeneratedTextMapper;
import com.ruoyi.tag.mapper.TagsInfoMapper;
import com.ruoyi.middleware.redis.utils.RedisCache;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.classify.mapper.HsContentTagMapper;
import com.ruoyi.classify.domain.HsContentTag;
import com.ruoyi.classify.service.IHsContentTagService;

/**
 * 内容标签关联Service业务层处理
 *
 * @author lzk
 * @date 2025-06-17
 */
@Service
public class HsContentTagServiceImpl implements IHsContentTagService {
    @Autowired
    private HsContentTagMapper hsContentTagMapper;
    @Autowired
    private HsGeneratedTextMapper hsGeneratedTextMapper;
    @Autowired
    private TagsInfoMapper tagsInfoMapper;
    @Autowired
    private OpenAiChatModel chatModel;
    @Autowired
    private RedisCache redisCache;

    private static final String TASK_PROGRESS_KEY_PREFIX = "tagging_task_progress:";

    @Override
    public HsContentTag selectHsContentTagById(Long id) {
        HsContentTag result = hsContentTagMapper.selectHsContentTagById(id);
        // 添加调试日志
        if (result != null) {
            System.out.println("查询到的标签数据: ID=" + result.getId() +
                    ", userTagId=" + result.getUserTagId() +
                    ", tagName=" + result.getTagName() +
                    ", topicId=" + result.getTopicId());
        }
        return result;
    }

    @Override
    public List<HsContentTag> selectHsContentTagList(HsContentTag hsContentTag) {
        return hsContentTagMapper.selectHsContentTagList(hsContentTag);
    }

    @Override
    public int insertHsContentTag(HsContentTag hsContentTag) {
        return hsContentTagMapper.insertHsContentTag(hsContentTag);
    }

    @Override
    public int updateHsContentTag(HsContentTag hsContentTag) {
        return hsContentTagMapper.updateHsContentTag(hsContentTag);
    }

    @Override
    public int deleteHsContentTagByIds(Long[] ids) {
        return hsContentTagMapper.deleteHsContentTagByIds(ids);
    }

    @Override
    public int deleteHsContentTagById(Long id) {
        return hsContentTagMapper.deleteHsContentTagById(id);
    }

    @Override
    public int batchUpdateVerify(List<Long> ids, int isVerified) {
        if (ids == null || ids.isEmpty()) return 0;
        return hsContentTagMapper.batchUpdateVerify(ids, isVerified);
    }
}